//
//  HNSH_TongZhengSuspensionView.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/16.
//

#import "HNSH_TongZhengSuspensionView.h"

#import "HNSH_TZXFEDViewController.h"

@implementation HNSH_TongZhengSuspensionShowView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor colorWithHexString:@"#FEEAC1"];
        [self configUI];
        self.userInteractionEnabled = YES;
        self.layer.cornerRadius = self.height/2.0f;
        self.layer.masksToBounds = YES;
        self.layer.borderColor = [[UIColor colorWithHexString:@"#FFC5BF"]CGColor];
        self.layer.borderWidth = 1.0f;
    }
    return self;
}

- (void)setXfedString:(NSString *)xfedString {
    _xfedString = xfedString;
}

- (void)configUI {
    [self addSubview:self.titleLabel];
    [self addSubview:self.showButton];
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]init];
        _titleLabel.frame = CGRectMake(12, 0, 120, self.height);
        _titleLabel.textColor = [UIColor colorWithHexString:@"#B45003"];
        _titleLabel.font = [UIFont boldSystemFontOfSize:12];
    }
    return _titleLabel;
}

- (UIButton *)showButton {
    if (!_showButton) {
        _showButton = [UIButton buttonWithType:UIButtonTypeCustom];
        _showButton.frame = CGRectMake(self.width-35-42, 0, 42, self.height);
        [_showButton setTitle:@"查看" forState:UIControlStateNormal];
        [_showButton setTitleColor:[UIColor colorWithHexString:@"#FF004E"] forState:UIControlStateNormal];
        _showButton.titleLabel.font = [UIFont boldSystemFontOfSize:12];
        [_showButton setImage:[UIImage imageNamed:@"tz_alert_more_icon"] forState:UIControlStateNormal];
        [_showButton HNSH_layoutButtonWithEdgeInsetsStyle:HHZXButtonStyleTextLeft imageTitleSpace:0];
        WeakSelf(weakSelf);
        [[_showButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            HNSH_TZXFEDViewController *vc = [[HNSH_TZXFEDViewController alloc]init];
            vc.account_type = @"50";
            vc.xfedString = weakSelf.xfedString;
            [[UIViewControllerHelper findCurrentShowingViewController].navigationController pushViewController:vc animated:YES];
        }];
    }
    return _showButton;
}

@end

@interface HNSH_TongZhengSuspensionView ()

/* closeButton */
@property (nonatomic, strong) UIButton *closeButton;

@end

@implementation HNSH_TongZhengSuspensionView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        [self configUI];
    }
    return self;
}

- (void)configUI {
    UIButton *activeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    activeButton.frame = CGRectMake(self.width-56, 14, 56, 52);
    [activeButton setImage:[UIImage imageNamed:@"tz_alert_icon"] forState:UIControlStateNormal];
    [self addSubview:activeButton];
    activeButton.userInteractionEnabled = YES;
    WeakSelf(weakSelf);
    [[activeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        UIButton *button = x;
        button.selected = !button.selected;
        if (weakSelf.showBlock) {
            weakSelf.showBlock(button.isSelected);
        }
        
    }];
    
    UIButton *closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
    closeButton.frame = CGRectMake(self.width-14, 0, 14, 14);
    [closeButton setImage:[UIImage imageNamed:@"tz_alert_close"] forState:UIControlStateNormal];
    [self addSubview:closeButton];
    self.closeButton = closeButton;
    closeButton.userInteractionEnabled = YES;
    [[closeButton rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        if (weakSelf.closeBlock) {
            weakSelf.closeBlock();
        }
        [weakSelf removeFromSuperview];
    }];
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
